home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 14 / Mac Magazin and MacEasy Magazine CD - Issue 14.iso / Wissenschaft & Technik / IngisWDEF ƒ / Demo ƒ / Simple ƒ / CustomStubs.p next >
Text File  |  1995-08-18  |  7KB  |  182 lines

  1. { *** DEMO FOR the IngisWDEF WDEF building package *** }
  2.  
  3. {© 1994-1995 by Ingemar Ragnemalm}
  4. {You may use it freely as long as credits are given in the final program.}
  5.  
  6.  
  7. {A simple example window. Rounded rect with a drag bar that is narrower than the content region. Window name}
  8. {not drawn; the drag area is painted blue/black. Supports close box but no zoom or grow boxes.}
  9. {}
  10. {In this example, many routines are left empty. Only the folowing routines are used: GetCloseBox, DrawCloseBox,}
  11. {DrawHitCloseBox, DrawDragBar and BuildCustomRegions. Can it be simpler?}
  12.  
  13.  
  14. {This unit holds all custom code}
  15.  
  16. unit CustomStubs;
  17.  
  18. interface
  19.     uses
  20. {$IFC UNDEFINED THINK_PASCAL}
  21.         Types, QuickDraw, ToolUtils, Windows, 
  22. {$ENDC}
  23.         IngisWDEFUtils;
  24.  
  25.     procedure GetGrowRgn (varCode: integer; macWindow: WindowPeek; var growRgn: RgnHandle);
  26.     procedure GetCloseBox (varCode: integer; dragBar: RgnHandle; var closeBox: Rect);
  27.     procedure GetZoomBox (varCode: integer; dragBar: RgnHandle; var zoomBox: Rect);
  28.     procedure DrawCloseBox (varCode: integer; macWindow: WindowPeek; closeBox: Rect; colorFlag: Boolean);
  29.     procedure DrawZoomBox (varCode: integer; macWindow: WindowPeek; zoomBox: Rect; colorFlag: Boolean);
  30.     procedure DrawHitCloseBox (varCode: integer; macWindow: WindowPeek; closeBox: Rect; colorFlag: Boolean);
  31.     procedure DrawHitZoomBox (varCode: integer; macWindow: WindowPeek; zoomBox: Rect; colorFlag: Boolean);
  32.     procedure DrawDragBar (varCode: integer; macWindow: WindowPeek; dragBar: RgnHandle; colorFlag: Boolean);
  33.     procedure BuildCustomRegions (varCode: integer; theRect: Rect; contRgn, dragRgn: RgnHandle);
  34.     procedure DrawScrollFrame (varCode: integer; macWindow: WindowPeek; theRect: Rect);
  35.     procedure DrawTheGrowIcon (varCode: integer; macWindow: WindowPeek; theRect: Rect; growRgn: RgnHandle; colorFlag: Boolean);
  36.     procedure InitMyWindow (varCode: integer; macWindow: WindowPeek);
  37.     procedure DisposeMyWindow (varCode: integer; macWindow: WindowPeek);
  38.  
  39. {** Constants **}
  40.     const
  41.         kFrameWidth = 1;        { Thickness of frame around window. 1 is normal.}
  42.         kShadowLength = 1;        { Size of drop shadow. 1 is normal.}
  43.         kMinDepthForColor = 4;    { Smallest pixel size for color. 8 (256 colors) is normal. }
  44.         kMinWidth = 100;        { Limits for the dragging rectangle? }
  45.         kMinHeight = 100;
  46.  
  47. implementation
  48.  
  49. {*****************************************************************************}
  50. { GetGrowRgn}
  51. {        Return the region with the grow icon, if any.}
  52. { *****************************************************************************}
  53.  
  54.     procedure GetGrowRgn (varCode: integer; macWindow: WindowPeek; var growRgn: RgnHandle);
  55.     begin
  56. {We don't support resizing}
  57.     end;
  58.  
  59. {*****************************************************************************}
  60. { GetCloseBox}
  61. {        Pass back a rectangle which encloses the close box of the window}
  62. { *****************************************************************************}
  63.  
  64.     procedure GetCloseBox (varCode: integer; dragBar: RgnHandle; var closeBox: Rect);
  65.     begin
  66.         with dragBar^^.rgnBBox do
  67.             SetRect(closeBox, left + 5, top + 3, left + 5 + (bottom - top - 4) - 2, bottom - 3);
  68.     end;
  69.  
  70.     procedure GetZoomBox (varCode: integer; dragBar: RgnHandle; var zoomBox: Rect);
  71.     begin
  72. {No zoom box}
  73.     end;
  74.  
  75. {*****************************************************************************}
  76. { Draw close box and zoom box, in normal and hit state }
  77. {        Draw the close box in "hit" state. This can be as simple as an InvertRect. }
  78. { *****************************************************************************}
  79.  
  80.     procedure DrawCloseBox (varCode: integer; macWindow: WindowPeek; closeBox: Rect; colorFlag: Boolean);
  81.     begin
  82.         StdCloseBox(closeBox, colorFlag);
  83.     end; {}
  84.     procedure DrawZoomBox (varCode: integer; macWindow: WindowPeek; zoomBox: Rect; colorFlag: Boolean);
  85.     begin
  86. {No zoom box}
  87.     end; {}
  88.     procedure DrawHitCloseBox (varCode: integer; macWindow: WindowPeek; closeBox: Rect; colorFlag: Boolean);
  89.     begin
  90. {InvertRect(closeBox);}
  91.         if colorFlag then
  92.             begin
  93. {$IFC UNDEFINED THINK_PASCAL}
  94.                 RGBForeColor(BoxShadowColor());
  95.                 RGBBackColor(BoxFillColor());
  96. {$ELSEC}
  97.                 RGBForeColor(BoxShadowColor);
  98.                 RGBBackColor(BoxFillColor);
  99. {$ENDC}
  100.             end;
  101.         DrawStdCloseHit(closeBox);
  102.     end; {}
  103.     procedure DrawHitZoomBox (varCode: integer; macWindow: WindowPeek; zoomBox: Rect; colorFlag: Boolean);
  104.     begin
  105.     end; {}
  106.  
  107. {*****************************************************************************}
  108. { DrawDragBar, BW and Color version}
  109. {        Draw the drag bar (not close box/zoom box)}
  110. { *****************************************************************************}
  111.  
  112.     procedure DrawDragBar (varCode: integer; macWindow: WindowPeek; dragBar: RgnHandle; colorFlag: Boolean);
  113.     begin
  114.         if colorFlag then
  115.             if macWindow^.hilited then
  116. {$IFC UNDEFINED THINK_PASCAL}
  117.                 RGBForeColor(BoxShadowColor())
  118.             else
  119.                 RGBForeColor(SurroundColor());
  120. {$ELSEC}
  121.                 RGBForeColor(BoxShadowColor)
  122.             else
  123.                 RGBForeColor(SurroundColor);
  124. {$ENDC}
  125.         PaintRgn(dragBar);
  126.     end; {DrawDragBar}
  127.  
  128. {*****************************************************************************}
  129. { BuildCustomRegions}
  130. {        Build the contents region and the drag bar region}
  131. { *****************************************************************************}
  132.  
  133.     procedure BuildCustomRegions (varCode: integer; theRect: Rect; contRgn, dragRgn: RgnHandle);
  134.         var
  135.             tmpRect: Rect;
  136.     begin
  137.         OpenRgn;
  138.         FrameRoundRect(theRect, 10, 10);
  139.         CloseRgn(contRgn);
  140.  
  141.         tmpRect := theRect;
  142.         InsetRect(tmpRect, 15, 0);
  143.         OffsetRect(tmpRect, 0, -18);
  144.         OpenRgn;
  145.         FrameRoundRect(tmpRect, 10, 10);
  146.         CloseRgn(dragRgn);
  147.     end; {BuildCustomRegions}
  148.  
  149. {*****************************************************************************}
  150. { DrawScrollFrame}
  151. {        Draw the scroll frame, if any (used both when resizing and when drawing the grow icon) }
  152. { *****************************************************************************}
  153.  
  154.     procedure DrawScrollFrame (varCode: integer; macWindow: WindowPeek; theRect: Rect);
  155.     begin
  156. {No scroll frame - no resizing}
  157.     end; {DrawScrollFrame}
  158.  
  159. {*****************************************************************************}
  160. { DrawTheGrowIcon, BW and Color version}
  161. {        Draw the grow icon, if any }
  162. { *****************************************************************************}
  163.  
  164.     procedure DrawTheGrowIcon (varCode: integer; macWindow: WindowPeek; theRect: Rect; growRgn: RgnHandle; colorFlag: Boolean);
  165.     begin
  166. {No grow}
  167.     end; {DrawTheGrowIcon}
  168.  
  169. {*****************************************************************************}
  170. { InitMyWindow and DisposeMyWindow }
  171. {        Can often be empty. Set the spareFlag in InitMyWindow if the variant should have a zoom box. }
  172. { *****************************************************************************}
  173.  
  174.     procedure InitMyWindow (varCode: integer; macWindow: WindowPeek);
  175.     begin
  176. {No zoom}
  177.     end; {}
  178.     procedure DisposeMyWindow (varCode: integer; macWindow: WindowPeek);
  179.     begin
  180.     end; {}
  181.  
  182. end.